package com.yunji.base.service;

import com.yunji.base.bo.ChangeBindBO;
import com.yunji.base.bo.StaffAccountModifyBO;
import com.yunji.base.convert.StaffConvert;
import com.yunji.base.dao.IStaffDao;
import com.yunji.base.dao.IStaffSiteDao;
import com.yunji.base.dto.StaffFiledDTO;
import com.yunji.base.vo.StaffVO;
import com.yunji.common.model.domain.StaffDO;
import com.yunji.common.utils.bean.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.Arrays;
import java.util.List;

/**
 * @Package com.yunji.user.service.impl
 * FileName:	StaffServiceImpl.java
 * Copyright:	Copyright © 2024 云集互联 All Rights Reserved
 * Company:		云集互联
 * @version: 1.0
 * @since: JDK 1.8.0_202
 * Create at:   2024-04-07 02:06:49
 * Description:
 * 员工接口实现
 * Modification History:
 * Author					Date					Version         Description
 * -------------------------------------------------------------------------------------
 * HuaAo0803@163.com	2024-04-07 02:06:49     1.0             1.0 Version
 */
@Service
public class StaffService {

    @Autowired
    private IStaffDao staffDao;

    @Autowired
    private IStaffSiteDao staffSiteDao;

    /**
     * @return List<Staff> 员工集合
     * @Title search
     * @Desc 查询员工列表
     * @Date 2024-04-15 17:11:45
     * @Param param 筛选信息
     */

//    public List<Staff> search(StaffParam param) {
//        return staffDao.search(param);
//    }

    /**
     * @param ids 员工ID数组
     * @Title search
     * @Desc 查询员工列表
     * @Date 2024-06-04 19:33:37.514
     * @Return List<Staff> 员工列表
     */

    public List<StaffDO> listByIds(Long... ids) {
        return staffDao.listByIds(Arrays.asList(ids));
    }

    /**
     * @Title select
     * @Desc 获取员工详情
     * @Date 2024-06-04 18:28:57.448
     * @Return Staff 员工详情
     */

//    public Staff select(Staff staff) {
//        StaffParam param = new StaffParam();
//        BeanUtils.clone(staff, param);
//        List<Staff> list = staffDao.search(param);
//        if (BeanUtils.isNull(list)) {
//            return null;
//        }
//        return list.get(0);
//    }
    public StaffDO select(Long id) {
        return staffDao.getById(id);
    }

    /**
     * @param staff 员工信息
     * @Title create
     * @Desc 创建员工信息
     * @Date 2024-06-04 09:58:45.551
     * @Return boolean 创建结果
     */

    public boolean create(StaffDO staff) {
        return staffDao.save(staff);
    }

    public boolean update(StaffDO staff) {
        return staffDao.updateById(staff);
    }

    /**
     * @Title changeAgent
     * @Desc 更换代理
     * @Date 2024-09-13 19:32:01.212
     * @Return boolean 修改结果
     */

    public boolean changeAgent(ChangeBindBO bo) {
        return staffDao.changeAgent(bo);
    }

    /**
     * @param ids 员工ID数组
     * @Title delete
     * @Desc 删除员工信息
     * @Date 2024-06-04 18:23:34.026
     * @Return boolean 删除结果
     */

    public boolean delete(Long... ids) {
        Assert.isTrue(BeanUtils.isNotNull(ids), "删除员工失败");
        return staffDao.removeBatchByIds(Arrays.asList(ids));
    }

    /**
     * @Title checkUsernameUnique
     * @Desc 检查账户唯一性
     * @Date 2024-06-03 18:25:40.495
     * @Return boolean 检查结果
     */

    public boolean existsPhone(Long excludeId, String phone) {
        return staffDao.existsPhone(excludeId, phone);
    }

    /**
     * @param phone 手机号码
     * @Title select
     * @Desc 获取员工详情
     * @Date 2024-06-05 11:35:50.589
     * @Return Staff 员工详情
     */
//    public Staff select(String phone) {
//        if (BeanUtils.isNull(phone)) {
//            return null;
//        }
//        StaffParam param = new StaffParam();
//        param.setStaffTel(phone);
//        List<Staff> list = staffMapper.search(param);
//        return BeanUtils.isNull(list) ? null : list.get(0);
//    }

    /**
     * 查询员工详细信息
     *
     * @param id 员工主键
     */
    public StaffVO selectStaffById(Long id) {
        StaffDO staff = staffDao.getById(id);
        return StaffConvert.domain2VO(staff, staffSiteDao);
    }

    /**
     * @param param 过滤条件
     * @Title searchTableField
     * @Desc 查询数据库表字段
     * @Date 2024-08-24 09:56:08.065
     * @Return List<String> 匹配结果
     */
    public List<String> searchTableField(StaffFiledDTO param) {
        return staffDao.searchTableField(param);
    }

    public List<StaffDO> listByManagerId(Long managerId) {
        return staffDao.listByManagerId(managerId);
    }

    public List<StaffDO> listByStaffIds(List<Long> staffIds) {
        return staffDao.listByIds(staffIds);
    }

    public List<StaffDO> listByAgentId(Long agentId) {
        return staffDao.listByAgentId(agentId);
    }

    public StaffDO getById(Long id) {
        return staffDao.getById(id);
    }

    public List<StaffDO> listByBelongId(Long belongId) {
        return staffDao.listByBelongId(belongId);
    }

    public boolean updateStaffAccount(StaffAccountModifyBO build) {
        return staffDao.updateStaffAccount(build);
    }

    public StaffDO getByPhone(String phone) {
        return staffDao.getByPhone(phone);
    }
}
